package com.sky.es.api;

import com.sky.es.api.request.CreateProductDocReuqest;
import com.sky.es.entity.ProductDoc;
import com.sky.es.service.ProductEsService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yangsk
 */
@RestController
@RequestMapping("/es/apis")
public class EsSpringDataAPI {
    @Autowired
    private ProductEsService productEsService;

    @ApiOperation(value = "创建索引文档接口", notes = "创建索引文档接口")
    @PostMapping("/add")
    public void addProuctDoc(@RequestBody CreateProductDocReuqest reuqest){
        productEsService.createProductDoc(reuqest);
    }

    @ApiOperation(value = "id查询文档", notes = "根据文档id，查询文档内容")
    @ApiImplicitParam(name="id",value="文档id",required = true,dataType ="String",paramType = "path")
    @GetMapping("/{id}")
    public ProductDoc findById(@PathVariable("id")String id){
        return productEsService.findById(Long.parseLong(id));
    }
    @ApiOperation(value = "商品名称查询文档", notes = "商品名称，查询文档内容")
    @GetMapping("/name")
    public List<ProductDoc> findByName(@RequestParam("name")String name){
        return productEsService.findByName(name);
    }
}
